import { PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, Column } from 'typeorm'
import dayjs from 'dayjs'

export abstract class BaseEntity {
    @PrimaryGeneratedColumn()
    id: number

    @CreateDateColumn({
        comment: '创建时间',
        transformer: {
            to: (value: Date) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'),
            from: (value: Date) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
        }
    })
    createdAt: Date

    @UpdateDateColumn({
        comment: '更新时间',
        transformer: {
            to: (value: Date) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'),
            from: (value: Date) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
        }
    })
    updatedAt: Date

    @Column({
        nullable: true,
        comment: '创建人',
        length: 50
    })
    createdBy: string

    @Column({
        nullable: true,
        comment: '更新人',
        length: 50
    })
    updatedBy: string
}
